package models

import (
	// "time"
	"fmt"

	"xorm.io/builder"
)

type Studentsign struct {
	Id       int    `xorm:"not null pk autoincr comment('自增主键') INT(11)"`
	IdNumber string `xorm:"comment('身份证号') VARCHAR(18)"`
	Phone    string `xorm:"comment('手机号') VARCHAR(64)"`
	Imgurl   string `xorm:"comment('签名地址') VARCHAR(255)"`
	Contract string `xorm:"comment('签名地址') VARCHAR(255)"`
}

func (c *Studentsign) Save() bool {
	var (
		err error
	)
	if _, err = engine.Insert(c); err != nil {
		return false
	}
	return true
}

func (c *Studentsign) Edit(who ...string) bool {
	var (
		err error
	)
	_, err = engine.ID(c.Id).Cols(who...).Update(c)
	if err != nil {
		fmt.Println(err.Error())
		return false
	}
	return true
}

func (c *Studentsign) GetOneStudentsignById(filter builder.Cond) (list Studentsign, err error) {
	_, err = engine.Table("dts_studentsign").And(filter).Get(&list)
	return list, err
}

// GetStudentSign 获取一条最新的记录
func (m *Studentsign) GetStudentSign(idNumber, phone string) (bool, error) {
	return engine.Table("dts_studentsign").Where("id_number=?", idNumber).OrderBy("id desc").Limit(1).Get(m)
}
